class gameMovieClip extends egret.MovieClip{
	private mRepeatCount:number;
	private mMcName:string;
	private data:any;
	private texture:any = null;
	private isAutoPlay:boolean = false;
	private isNeedRemove:boolean = false;
	private stopFrame:number = 1;
	public isCenter:boolean = false;
	public constructor(_mcName:string, _repeatCount:number = 1, _isAutoPlay:boolean = true, _isNeedRemove:boolean = true) {
		super();
		this.mRepeatCount = _repeatCount;
		this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
		this.mMcName = _mcName;
		this.isAutoPlay = _isAutoPlay;
		this.isNeedRemove = _isNeedRemove;
		this.loadMc(_mcName);
	}
	public gotoAndStop(_frame:any):void
	{
		this.stopFrame = _frame;
		if(this.texture) super.gotoAndStop(_frame);

	}
	private loadMc(mcName:string):void
	{
		var self = this;
		RES.getResAsync(mcName+"_json", function(_data:any, _key:string){
			self.data = _data;
			RES.getResAsync(mcName+"_png", function(_texture:egret.Texture, _key:string){
				self.texture = _texture;
				if(self.isAutoPlay)
				{
					self.playMc();
				}	
				else
				{
					self.gotoAndStop(self.stopFrame);
				}
				
			}, this);
			
		}, this);
		
	}



	private playMc():void
	{
		let mcDataFactory:egret.MovieClipDataFactory = new egret.MovieClipDataFactory(this.data, this.texture);
		this.movieClipData = mcDataFactory.generateMovieClipData(this.mMcName);
		if(this.isCenter)
		{
			this.x = (Game.stage.stageWidth - this.width) / 2;
			this.y = (Game.stage.stageHeight - this.height)  / 2;
		}
		this.gotoAndPlay(0, this.mRepeatCount);
		if(this.mRepeatCount == 1)
		{
			this.addEventListener(egret.Event.COMPLETE, this.onPlayEnd, this);
		}
	}

	private onPlayEnd(e:egret.Event):void
	{
		if(this.isNeedRemove)
		{
			//UIUtil.removeChildFromParent(this);
			this.parent.removeChild(this);
		}
			
	}

	private onRemoved(e:egret.Event):void
	{
		this.removeEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
		if(this.hasEventListener(egret.Event.COMPLETE))
		{
			this.removeEventListener(egret.Event.COMPLETE, this.onPlayEnd, this);
		}
	}
}